package com.yaxin.swaggertest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.android.volley.Response;
import com.android.volley.VolleyError;

import io.swagger.client.ApiInvoker;
import swagger.account.api.LoginApi;
import swagger.account.api.UserApi;
import swagger.account.model.AmendNickNameReq;
import swagger.account.model.AmendNickNameRes;
import swagger.account.model.BaseLoginRes;
import swagger.account.model.LoginReq;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClick(View view) {
        ApiInvoker.initializeInstance();
        ApiInvoker.getInstance().addDefaultHeader("biuoo-from", "android");
        ApiInvoker.getInstance().addDefaultHeader("biuoo-token", "83726cdbf0a34215a9bee4336614d5b4");
        LoginApi loginApi = new LoginApi();
//        loginApi.addHeader("biuoo-token", "83726cdbf0a34215a9bee4336614d5b4");
//        loginApi.addHeader("biuoo-from", "android");
        LoginReq loginReq = new LoginReq();
        loginReq.setMobile(1872561894);
        loginReq.setPassword("qqqqqq");
        loginApi.loginPost(loginReq, new Response.Listener<BaseLoginRes>() {
            @Override
            public void onResponse(BaseLoginRes response) {
                Log.e("yy", "onResponse:" + response.getCode());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("yy", "VolleyError:" + error.getMessage());
            }
        });

        UserApi userApi=new UserApi();
        AmendNickNameReq amendNickNameReq=new AmendNickNameReq();
        amendNickNameReq.setNickName("网络返回swagger");
        userApi.amendNickNamePost(amendNickNameReq, new Response.Listener<AmendNickNameRes>() {
            @Override
            public void onResponse(AmendNickNameRes response) {
                Log.e("yy", "onResponse:" + response.toString());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("yy", "VolleyError:" + error.getMessage());
            }
        });

    }
}
